package com.team7.controller;

import com.team7.dao.CourseSubjectDao;
import com.team7.entity.Subject;
import com.team7.service.CourseManageService;
import com.team7.vo.CommonResult;
import com.team7.vo.CourseTypeVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.bind.SchemaOutputResolver;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.UUID;

/**
 * @program: team7-object
 * @description:
 * @author: 田宏洋
 * @create: 2021-10-18 19:43
 **/

@RestController
@RequestMapping("core/courseManage")
public class CourseSubjectManageController {


    @Resource
    private CourseManageService courseManageService;
    @PostMapping("findCourseType/{page}/{limit}")
    @ApiOperation("分页查询课程分类")
    public CommonResult findCourseTypeByPage(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit, @RequestBody CourseTypeVo courseTypeVo){
        CommonResult courseByPage = courseManageService.findCourseByPage(page, limit, courseTypeVo);
        return courseByPage;
    }
    @PostMapping("insertCourseType")
    @ApiOperation("添加课程分类")
    public CommonResult insertCourseType(@RequestBody Subject subject){
        subject.setSort(0);
        String substring = UUID.randomUUID().toString().replace("-", "").substring(0, 19);
        if("0".equals(subject.getParentId())&&subject.getId().equals("0")){
            subject.setId(substring);
        }else {
            subject.setParentId(subject.getId());
            subject.setId(substring);
            subject.setSort(1);
        }
        subject.setStatusId("0");
        LocalDateTime now = LocalDateTime.now();
        String sj = now.toString();
        subject.setGmtCreate(sj);
        subject.setGmtModified(sj);
        return courseManageService.insertCourseType(subject);
    }
    @ApiOperation("分页查询正常的课程分类")
    @PostMapping("/findsubjectByStatus/{page}/{limit}")
    public CommonResult findsubjectByStatus(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit){
        CommonResult commonResult = courseManageService.findsubjectByStatus(page, limit);
        return commonResult;
    }

    @PostMapping("/updateCourseType")
    @ApiOperation("修改课程分类")
    public CommonResult updateCourseType(@RequestBody Subject subject){
        return courseManageService.updateCourseType(subject);
    }
    @PostMapping("/deleteCourseType")
    @ApiOperation("删除课程分类")
    public CommonResult deletesubject(@RequestBody Subject subject){
        String id = subject.getId();
        return courseManageService.deleteCourseType(id);
    }

    @PostMapping("/changeStatusId")
    @ApiOperation("修改课程分类的状态")
    public CommonResult changeStatusId(@RequestBody CourseTypeVo courseTypeVo){
        return courseManageService.changeStatusId(courseTypeVo);
    }
    @ApiOperation("根据课程分类id查找其父id")
    @GetMapping("/findPidByid/{pid}")
    public String findPidByid(@PathVariable String pid){
        return courseManageService.findPidByid(pid);
    }
}
